﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Net.Mail;
using System.Data;


    public class LogFile
    {
        readonly static log4net.ILog loggerGenerate = log4net.LogManager.GetLogger("RollingFileAppender");
        readonly static log4net.ILog loggerEmail = log4net.LogManager.GetLogger("SmtpAppender");

        public static void Write(ELogType logType, string sMessage)
        {
            if (logType == ELogType.Debug)
            {
                loggerGenerate.Debug(sMessage);
            }
            else if (logType == ELogType.Error)
            {
                loggerGenerate.Error(sMessage);
            }
            else if (logType == ELogType.Fatal)
            {
                loggerGenerate.Fatal(sMessage);
            }
            else if (logType == ELogType.Info)
            {
                loggerGenerate.Info(sMessage);
            }
            else if (logType == ELogType.Warn)
            {
                loggerGenerate.Warn(sMessage);
            }
        }

        //public static void SendEmail(ELogType logType, string sMessage)
        //{
        //    if (logType == ELogType.Debug)
        //    {
        //        loggerEmail.Debug(sMessage);
        //    }
        //    else if (logType == ELogType.Error)
        //    {
        //        loggerEmail.Error(sMessage);
        //    }
        //    else if (logType == ELogType.Fatal)
        //    {
        //        loggerEmail.Fatal(sMessage);
        //    }
        //    else if (logType == ELogType.Info)
        //    {
        //        loggerEmail.Info(sMessage);
        //    }
        //    else if (logType == ELogType.Warn)
        //    {
        //        loggerEmail.Warn(sMessage);
        //    }
        //}


        // Methods
        public static void SendEmail(string sMesasge)
        {

            string[] strArray = new string[2];// info.info1("", "shopemail").ToString().Split(new char[] { '@' });
            strArray[0] = "alvin@haolicard.com";
            strArray[1] = "xinnetvip.com";
            string body = "尊敬的用户您好：<br />请您点击以下链接创建帐户密码！这个链接24小时内有效";
            string str4 = body;
            string str5 = str4 + "<br />" + fun.geturl1("") + "forget2.aspx?memberid=<br />如果您不能点击以上按钮，请将该链接复制到浏览器地址栏中访问，也可以完成新密码的创建！";
            body = str5 + "如有任何疑问，请访问" + info.info1("", "shopname") + "帮助中心(" + fun.geturl1("") + "news.aspx?nid=8)，或者与" + info.info1("", "shopname") + "客服取得联系。<Br />联系电话：" + info.info1("", "shoptel") + "";
            SmtpClient client = new SmtpClient();

            client.Host = "smtp." + strArray[1]; //.xinnetvip.com

            client.Credentials = new System.Net.NetworkCredential(strArray[0], info.info1("", "shopwebmsg").ToString());
            MailMessage message = new MailMessage(strArray[0], "zyh_100@126.com", "" + info.info1("", "shopname") + "：请继续创建帐户密码", body);


            try
            {

                client.Send(message);
                //SQLAccess.DoSql("update  DB_Member set videcode='" + videcode + "' where memberid=" + table.Rows[0]["memberid"].ToString() + "");

            }
            catch (Exception ex)
            {
            }
            HttpContext.Current.Response.Write("<script>location.href='forget1.aspx';</script>");
        }


    }

    public enum ELogType
    {
        Debug = 0,
        Error,
        Fatal,
        Warn,
        Info
    }
